package com.whfc.wxmp.api.fse.controller;

import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.JSONUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.entity.param.warn.AppWarnHandleParam;
import com.whfc.fse.dto.FseWarnDetailDTO;
import com.whfc.wxmp.api.fse.service.WxFseWarnService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @Description: 特种设备报警接口
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/11/30 8:49
 */
@RestController
@RequestMapping("mp/api/")
public class WxFseWarnController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxFseWarnService wxFseWarnService;


    /**
     * 查询特种设备报警消息详情
     *
     * @param loginUser
     * @param warnId
     * @return
     */
    @GetMapping(value = {"fse/warn/detail", "msg/warn/fse/detail"})
    public Result getFseWarnMsgDetail(@CurrentWxUser WxUser loginUser,
                                      @RequestParam("warnId") Integer warnId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "查询特种设备报警消息详情", RequestConetxtUtil.getParameters());
        FseWarnDetailDTO warnDetail = wxFseWarnService.getFseWarnDetail(warnId);
        return ResultUtil.success(warnDetail);
    }

    /**
     * 处理特种设备报警消息
     *
     * @param loginUser
     * @param body
     * @return
     */
    @PostMapping(value = {"fse/warn/handle", "msg/warn/fse/handle"})
    public Result handleFseWarn(@CurrentWxUser WxUser loginUser,
                                @RequestBody @Validated AppWarnHandleParam body) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "处理特种设备报警消息", JSONUtil.toString(body));
        wxFseWarnService.handleFseWarn(loginUser, body);
        return ResultUtil.success();
    }


}
